<script type="text/javascript">
<!--
	function getData(ojb,opt) {	
	
		if(opt==1) {		
			$.ajax({
			  url: "/backend/common/ajax_motor.php",
			  context: document.body,			 
			  data: 'id=' + $('#manu_id').val(),
			  contentType: "application/x-www-form-urlencoded;charset=UTF-8",			  			 
			  success: function(data){				  
				  $('#model_id').html(data);
			  }
			});
		} else if (opt==2) {
			$.ajax({
			  url: "/backend/common/ajax_motor.php",
			  context: document.body,			 
			  data: 'type=' + $('#type').val(),	
			  contentType: "application/x-www-form-urlencoded;charset=UTF-8",		 
			  success: function(data){				  
				  $('#manu_id').html(data);
				  $('#model_id').html('<option value="">-------</option>');
			  }
			});
		}
	}
//-->
</script>


<?php

# CLASS_JCAS.PHP

# Core of the software, contains jcas class

# Included in every pages



if (!defined('INDEX')) exit;
$arrType = array ('Xe máy','Ô tô');

//var_dump($arrayManu);
class jcas {

	###########################################################################################

	// Draw input, auto obtain value when editing item

	# draw_input(input_type,input_name,input_width,input_height,input_default_value,anti_duplicated_value)

	function draw_input($type,$name,$width,$height,$value,$check_duplicated, $attr='')

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;



		// Get data for input

		if($_POST[$name]) $data = $_POST[$name];

		else

		{

			// Edit content

			if ($content[$name] )
			if (trim($content[$name])=='Thương hiệu xe của bạn là gì?'
			|| trim($content[$name])=='Model xe của bạn là gì?')
			$data = '';
			else
			$data = $content[$name];

			// Edit cat

			elseif ($cat[$name] && !$content) $data = $cat[$name];

			// Add new content/cat

			else

			{

				if($type!='checkbox' && $type!='radio') $data = $value;

			}

		}



		$result = '';

		switch ($type)

		{

			// Incorrect input type

			default:

				$result .= '<font color="red">Unknown input type</font>';

				break;

					

				// Hidden input

			case 'hidden':

				$result .= '<input type="hidden" name="'.$name.'" " value="'.$data.'" />';

				break;

					

				// Text field input

			case 'text':

				$result .= '<input type="text" name="'.$name.'" style="width:'.$width.'" value="'.$data.'" '.$attr.'/>';

				if($check_duplicated) $result .= '<input type="hidden" name="jcas_check_'.$name.'" value="yes">';

				break;

					

				// Textfield with date

			case 'text_date':

				//$result .= '<div style="float:left; padding-right:5px"><input name="'.$name.'" type="text" value="'.$data.'" size="10" ></div><div style="float:left"><img src="images/icon/icon_calendar.gif" width=16 height=16 onClick="showCalendar(\'\',\''.$name.'\',\''.$name.'\',\'\',\''.$name.'\',0,20,1)" style="cursor: pointer" />  <font class="info">(dd/mm/yyyy)</font></div>';
				$result .= '<div style="float:left; padding-right:5px"><input name="'.$name.'" type="text" value="'.$data.'" size="10" class="date-pick"></div><div style="float:left">  <font class="info">(dd-mm-yyyy)</font></div>';

				break;

					

				// Password input

			case 'password':

				$result .= '<input type="password" name="'.$name.'" style="width:'.$width.'" value="" />';

				// Display password-recognizing field

				$result .= '<input type="hidden" name="jcas_password_'.$name.'" value="yes"> ';

				// Check if not allow duplicated

				if($check_duplicated) $result .= '<input type="hidden" name="jcas_check_'.$name.'" value="yes">';

				break;

					

				// Textarea input

			case 'textarea':

				$result .= '<textarea name="'.$name.'" style="width:'.$width.';height:'.$height.'">'.$data.'</textarea>';

				break;

					

				// Textarea input

			case 'textarea_html':

				$result .= '<textarea class="editor" name="'.$name.'" style="width:'.$width.';height:'.$height.'">'.$data.'</textarea>';

				break;

					

				// File field input

			case 'file':

				if($cat[$name] || $content[$name])

				{

					if (strpos($data, 'http://')!==false):
					$result .= '<img src="'.$data.'" height="100"/>';

					else:
					$result .= '<img src="'.'../'.rtrim($cfg['upload_folder'],'/').'/'.$data.'" height="100"/>';

					if(!file_exists($data)) {

						$result .= ' <font color="red">('.$lang['file_not_found_on_hdd'].')</font>';
					}
					$result .= '&nbsp;&nbsp;&nbsp;&nbsp;<input type="hidden" name="'.$name.'" value="'.$data.'"><input type="checkbox" name="jcas_delete_'.$name.'" class="box" value="yes">'.$lang["delete_file"].'<br /><b>&raquo;</b> <u>'.$lang["replace_with_file"].'</u> ';

					endif;




				}

				$result .= '<input type="file" name="'.$name.'" style="width:'.$width.'" />';

				break;

					

				// Radio input

			case 'radio':

				$result .= '<input type="radio" class="box" name="'.$name.'" value="'.$value.'" '.(($data==$value)?'checked="true"':'').' />';

				break;

					

				// Checkbox input

			case 'checkbox':

				$result .= '<input type="checkbox" class="box" name="jcas_cb_'.$name.'" value="'.$value.'" '.(($data==$value)?'checked="true"':'').' onClick="cbset_value(\'frm_jcas\',\''.$name.'\',\'jcas_cb_'.$name.'\');" /><input type="text" name="'.$name.'" value="'.$data.'" style="width:0px;height:0px;border:0px" /> ';

				break;
			case 'select':
				$result .= '<select class="smallinput" name="'.$name.'">';
				$result .= "\n$attr";
				foreach($value as $id=>$val):
				if($data == $id){
					$result .= '<option value="'.$id.'" selected="selected">'.$val.'</option>';
				}else{
					$result .= '<option value="'.$id.'">'.$val.'</option>';
				}

				endforeach;
				$result .= '</select>';
				break;
		}

		return $result;

	}

	function draw_select($name,$value, $attr='')

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;



		// Get data for input

		if($_POST[$name]) $data = $_POST[$name];

		else

		{
			// Edit content

			if ($content[$name] )
			$data = $content[$name];

			// Edit cat

			elseif ($cat[$name] && !$content) $data = $cat[$name];

			// Add new content/cat

		}



		$result = '';
		$result .= '<select class="smallinput" id="'.$name.'" name="'.$name.'" onChange="getData('.$name.',2);">';
		$result .= "\n$attr";
		foreach($value as $id=>$val):
		if($data == $id){
			$result .= '<option value="'.$id.'" selected="selected">'.$val.'</option>';
		}else{
			$result .= '<option value="'.$id.'">'.$val.'</option>';
		}
		endforeach;
		$result .= '</select>';



		return $result;

	}

	###########################################################################################

	// Draw move form

	function draw_form_move($table,$field_move,$level)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		if($table)

		{

			$result = '<table cellpadding=0 cellspacing=0 border=0><tr>';

			$result .= '<td>'.$lang["move_selected_to"].': </td>';

			$result .= '<td>'.$this->draw_select_cat($table,$field_move,'',$level,0).'</td>';

			$result .= '<td><input type="submit" name="move" class="button" value="OK"></td>';

			$result .= '<input type=hidden name="pg" value="'.get('pg').'" />';

			$result .= '</tr></table>';

		}

		else $result = '&nbsp;';



		return $result;

	}



	###########################################################################################

	// Draw search form (displayed on the top-right of every showing-content page)

	function draw_form_search()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;



		$result = "";

		if($mdl_cfg['search_fields'])

		{

			$search_option = "";

			foreach ($mdl_cfg['search_fields'] as $mdl_field=>$mdl_title)

			$search_option .= '<option value="'.$mdl_field.'" '.(($_GET["search_field"]==$mdl_field)?'selected':'').'>'.$mdl_title.'</option>';

			$result = js_validate("keyword","frm_search");

			$result .= '<table cellpadding=1 cellspacing=0 border=0>

			<form name="frm_search" method="get" action="'.$index_url.'&p=search" onSubmit="return validate_frm_search()">

			<input type="hidden" name="mdl" value="'.$_GET["mdl"].'" />

			<input type="hidden" name="p" value="search" />	

			<tr>	

				<td>'.$lang["search"].'</td>

				<td><select name="search_field" >'.$search_option.'</select> :</td>

				<td><input type="text" name="keyword" size="25" value="'.$_GET["keyword"].'" class="smallinput" /></td>

				<td><input type="submit" name="search" value="OK" class="button" /></td>

			</tr>

			</form>

			</table>';

		}

		else $result = '&nbsp;';



		return $result;

	}



	###########################################################################################

	// Draw sort form (displayed on the bottom-left of every showing-content page)

	function draw_form_sort()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$result = "";

		if($mdl_cfg['sort_fields'])

		{

			$sort_option = "";

			$no = 0;

			foreach ($mdl_cfg['sort_fields'] as $sort_field=>$sort_title)

			{

				$no += 1;

				$sort_option .= '<option value="'.$sort_field.'" '.(($_SESSION[get('mdl').'_content_sort_by']==$sort_field)?'selected':'').' '.(($no>1)?'style="color:red"':'').'>'.$sort_title.'</option>';

			}

			$result .= '<table border="0" cellspacing="0" cellpadding="0"><tr>';

			$result .= '<td>'.$lang["sort_by"].'</td>';

			$result .= '<td><select name="sort_by">'.$sort_option.'</select></td>';

			$result .= '<td><select name="sort_order" >

							<option value="asc" '.(($_SESSION[get('mdl').'_content_sort_order']=='asc')?'selected':'').'>'.$lang["ascending"].'</option>

							<option value="desc" '.(($_SESSION[get('mdl').'_content_sort_order']=='desc')?'selected':'').'>'.$lang["descending"].'</option>

							</select>

						</td>';

			$result .= '<td><input type="submit" class="button" name="submit" value="OK"   /></td>';

			$result .= '</tr></table>';



		}

		else $result = '&nbsp;';

		return $result;

	}



	###########################################################################################

	// Draw options list

	function draw_options($option_id)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$site_url = $index_url.'&p='.get('p').'&sp='.get('sp').'&cat_id='.get('cat_id').'&id='.get('id');

		if($mdl_cfg[$option_id.'_options'])

		{

			$result .= '<font color="#FFFFFF">'.$lang['display'].':</font> <select name="'.$option_id.'_options" onChange="menu_jump(this.options[this.selectedIndex].value);">';

			$no = 0;

			foreach ($mdl_cfg[$option_id.'_options'] as $link=>$title)

			{



				$no += 1;

				$selected = '';

				if(@eregi($option_id.'_option='.$_SESSION[get('mdl').'_'.$option_id.'_option'],$link)) $selected = 'selected';

				$result .= '<option value="'.$site_url.'&'.$link.'" '.$selected.' '.(($no>1)?'style="color:red"':'').'>'.$title.'</option>';



			}

			$result .= '</select>';

		}

		else $result = '&nbsp;';



		return $result;

	}



	###########################################################################################

	// Draw jump list & search form

	function draw_jump_search()

	{

		$result = '<table width="100%"  border="0" cellspacing="0" cellpadding="2" >

				<tr>

				<td align="left">'.$this->draw_select_cat($_SESSION[get('mdl').'_cat_table'],'','',3,1).'</td>

				<td align="right">'.$this->draw_form_search().'</td>

				</tr>

				</table>';



		return $result;

	}



	###########################################################################################

	// Draw tab menu for each module

	function draw_tab()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$result = '';

		if(count($module[@$_GET['mdl']])>1)

		{

			$result .= '<table width="100%"  border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%"  border="0" cellspacing="0" cellpadding="0"><tr>';

			foreach ($module[@$_GET['mdl']] as $module_title => $module_url)

			{

				$result .= '<td width="150" class="'.((eregi('p='.$_GET['p'],$module_url) && eregi('mdl='.$_GET['mdl'],$module_url))?'tabtd':'tabtd_blur').'" align="center"><a href="'.$module_url.'&SID='.session_id().'">'.$module_title.'</a></td><td width="5">&nbsp;</td>';

			}

			$result .= '<td >&nbsp;</td></tr></table></td></tr><tr><td class="tabtd" height="2"></td></tr></table>';

		}

		else $result = '&nbsp;';


		//var_dump($module[@$_GET['mdl']]);
		return $result;

	}



	###########################################################################################

	// Draw drop list for category (in case use category)

	function draw_select_cat($table,$field_name,$field_select='name',$level=3,$go=0,$field_value='id',$case=1)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$result = "";

		if($table)

		{

			// Default values

			if(!$field_select) $field_select='name';

			if(!$field_value) $field_value='id';


			if(get('p') != 'search' )//&& get('p') != 'add_cat' && get('p') != 'add_content'

			{

				// cat or content

				if($cat) $item=$cat;

				if ($content) $item=$content;



				$data_cat_id = (($item[$field_name])?$item[$field_name]:$_POST[$field_name]);

			}
            
            $data_cat_id = $data_cat_id? $data_cat_id:$_GET[$field_name];
			$result .= '<select name="'.$field_name.'" '.(($go)?'onChange="menu_jump(this.options[this.selectedIndex].value);"':'').' class="smallinput">';



			// Select all cats

			$q_cat = $DB->query('SELECT * FROM '.$table.' WHERE active=1 and '.$field_value."<>'' ".(($_SESSION['admin_show_lang_id'])?'AND lang_id='.$_SESSION['admin_show_lang_id']:'').' ORDER BY sort ASC,'.$field_select.' ASC, created_time DESC');

			$total_cat = $DB->num_rows($q_cat);



			if($total_cat)

			{

				// List all cat variables

				for($x=0;$x<$total_cat;$x++)

				{

					$cat[$x] = $DB->result_array($q_cat,$x,"id,parent_id,$field_select".(($field_value!='id')?','.$field_value:''));

				}



				$result .= '<option value="" style="color:#666666 ">---'.(($go)?$lang["quick_jump"]:$lang["pls_select"]).'---</option>';



				// CAT LEVEL 1

				for($x1=0;$x1<$total_cat;$x1++)

				{

					$cat1_exist = false;

					if($cat[$x1]['parent_id'] == 0)

					{

						$result .= '<option value="'.(($go)?$index_url.'&p=show&sp=show_content&'.$field_name.'='.$cat[$x1][$field_value]:$cat[$x1][$field_value]).'" '.(($data_cat_id==$cat[$x1][$field_value])?'selected="selected"':'').' style="color:red">&#8250; '.$cat[$x1][$field_select].'</option>';

						$cat1_exist = true;

					}



					if($level>1 && $cat1_exist)

					{

						// CAT LEVEL 2

						for($x2=0;$x2<$total_cat;$x2++)

						{

							$cat2_exist = false;

							if($cat[$x2]['parent_id'] == $cat[$x1]['id'])

							{

								$result .= '<option value="'.(($go)?$index_url.'&p=show&sp=show_content&'.$field_name.'='.$cat[$x2][$field_value]:$cat[$x2][$field_value]).'" '.(($data_cat_id==$cat[$x2][$field_value])?'selected="selected"':'').' style="color:blue">--&#8250; '.$cat[$x2][$field_select].'</option>';

								$cat2_exist = true;

							}



							if($level>2 && $cat2_exist)

							{

								// CAT LEVEL 3

								for($x3=0;$x3<$total_cat;$x3++)

								{

									if($cat[$x3]['parent_id'] == $cat[$x2]['id'])

									{

										$result .= '<option value="'.(($go)?$index_url.'&p=show&sp=show_content&'.$field_name.'='.$cat[$x3][$field_value]:$cat[$x3][$field_value]).'" '.(($data_cat_id==$cat[$x3][$field_value])?'selected="selected"':'').' >----&#8250; '.$cat[$x3][$field_select].'</option>';

									}

								}

							}

						}

					}

				}

			}

			else $result .= '<option value="" style="color:#666666 ">-- '.$lang["no_cat_was_found"].' --</option>';

			$result .= '</select>';

		}

		else $result = '&nbsp;';



		return $result;

	}

	function draw_select_cat_motor($table,$field_name,$field_select='name',$go=0,$field_value='id', $case=1)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$result = "";

		if($table)

		{

			// Default values

			if(!$field_select) $field_select='name';

			if(!$field_value) $field_value='id';


			if(get('p') != 'search' )//&& get('p') != 'add_cat' && get('p') != 'add_content'

			{

				// cat or content

				if($cat) $item=$cat;

				if ($content) $item=$content;



				$data_cat_id = (($item[$field_name])?$item[$field_name]:$_REQUEST[$field_name]);
				if($case == 1){
				    $data_type = (($item['type'])?$item['type']:$_POST['type']);    
				}				
				else{
				    $data_type = (($item['manu_id'])?$item['manu_id']:$_REQUEST['manu_id']);
                        
				}
				

				$id = (($item['id'])?$item['id']:$_REQUEST['id']);

			}
            //$data_cat_id = $data_cat_id? $data_cat_id:$_GET[$field_name];
			if($case==1){
			 if($go){
			     
			     $result .= '<select name="'.$field_name.'" onChange="menu_jump(this.options[this.selectedIndex].value);" class="smallinput">';
			 }else{
			     $result .= '<select id="'.$field_name.'" name="'.$field_name.'" onChange="getData('.$field_name.',1);" class="smallinput">';
			 }
			     
			}			
			else{
			     $result .= '<select id="'.$field_name.'" name="'.$field_name.'" class="smallinput">'; 
			}
			


			// Select all cats
			if($case == 1){
			     $q_cat = $DB->query('SELECT * FROM '.$table.' WHERE type = "'.$data_type.'" and active=1 and '.$field_value."<>'' ".(($_SESSION['admin_show_lang_id'])?'AND lang_id='.$_SESSION['admin_show_lang_id']:'').' ORDER BY sort ASC,'.$field_select.' ASC, created_time DESC');
			}			
			else{
			     //var_dump('SELECT * FROM '.$table.' WHERE manu_id="'.$data_type.'" and active=1 and '.$field_value."<>'' ".(($_SESSION['admin_show_lang_id'])?'AND lang_id='.$_SESSION['admin_show_lang_id']:'').' ORDER BY sort ASC,'.$field_select.' ASC, created_time DESC');
                 $q_cat = $DB->query('SELECT * FROM '.$table.' WHERE manu_id="'.$data_type.'" and active=1 and '.$field_value."<>'' ".(($_SESSION['admin_show_lang_id'])?'AND lang_id='.$_SESSION['admin_show_lang_id']:'').' ORDER BY sort ASC,'.$field_select.' ASC, created_time DESC');
			}
			
			$total_cat = $DB->num_rows($q_cat);



			if($total_cat)

			{

				// List all cat variables

				for($x=0;$x<$total_cat;$x++)

				{

					$cat[$x] = $DB->result_array($q_cat,$x,"id,parent_id,$field_select".(($field_value!='id')?','.$field_value:''));

				}



				$result .= '<option value="" style="color:#666666 ">---'.(($go)?$lang["quick_jump"]:$lang["pls_select"]).'---</option>';



				// CAT LEVEL 1

				for($x1=0;$x1<$total_cat;$x1++)

				{

					$cat1_exist = false;

					if($cat[$x1]['parent_id'] == 0)

					{

						$result .= '<option value="'.(($go)?$index_url.'&p=show&id='.$id.'&'.$field_name.'='.$cat[$x1][$field_value]:$cat[$x1][$field_value]).'" '.(($data_cat_id==$cat[$x1][$field_value])?'selected="selected"':'').' style="color:red">&#8250; '.$cat[$x1][$field_select].'</option>';

						$cat1_exist = true;

					}



				}

			}

			else $result .= '<option value="" style="color:#666666 ">-- '.$lang["no_cat_was_found"].' --</option>';

			$result .= '</select>';

		}

		else $result = '&nbsp;';



		return $result;

	}



	###########################################################################################

	// Show language flags

	// return Flag list

	function draw_select_language()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session,$language;



		if(count($language) > 1)

		{

			if($cat) $item=$cat;

			if($content) $item=$content;



			$result .= '<tr>';

			$result .= '<td class="row1td"><strong>'.$lang['language'].'</strong> *</td>';

			$result .= '<td class="row1td"><select name="lang_id" >';

			foreach ($language as $id=>$code_title)

			{

				list($code,$title) = explode(",",$code_title);

				$result .= '<option value="'.$id.'" '.(($item)?(($item['lang_id'] == $id)?'selected=true':''):(($_SESSION['admin_show_lang_id'] == $id)?'selected=true':'')) .' style="color:red"> &#8250; '.$title.'</option>';

			}

			$result .= '</select></td>';

			$result .= '</tr>';

		}

		else $result .= '<input type="hidden" name="lang_id" value="'.$_GET['lang_id'].'" />';



		return $result;

	}



	###########################################################################################

	// Get category's values (when editing)

	function get_cat($cat_id)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		if($_SESSION[get('mdl').'_cat_table'])

		{

			$query = $DB->query('SELECT * FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE id="'.$cat_id.'"');

			$result = $DB->fetch_assoc($query);

		}

		return $result;

	}



	###########################################################################################

	// Get content's values (when editing)

	function get_content($id)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		if($tbl["content"])

		{

			$query = $DB->query('SELECT * FROM '.$tbl["content"].' WHERE id='.$id);
			$result = $DB->fetch_assoc($query);

		}

		return $result;

	}

	###########################################################################################

	// Execute query (insert, update) for adding, edting

	#query_type : "insert" or "update"

	#level : "cat" (execute query of category) or "content" (execute query of content)

	function execute_db($query_type,$table,$level)

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		$check_same_data = false;

		$result = '';

		// Excute query of cat

		if($level=="cat")

		{

			$item_id = $_GET['cat_id'];

			$_POST['jcas_sort'] = 10;

		}

		// Excute query of content

		else

		{

			$item_id = $_GET['id'];

			$_POST['jcas_sort'] = 100;

		}



		// Get post value

		foreach ($_POST as $query_field=>$query_value)

		{

			// Variable set by jcas

			if(!eregi("jcas_",$query_field))

			{

				// Check value if existing in database

				if(isset($_POST["jcas_check_".$query_field]))

				{

					if(@$DB->num_rows($DB->query('SELECT id FROM '.$table.' WHERE `'.$query_field.'`="'.$_POST[$query_field].'" '.(($query_type=='update')?'AND id!="'.$item_id.'"':'').'')))

					{

						$check_same_data = $query_field;

						break;

					}

				}

				// Check value if there is a password field

				// Then md5 twice

				if(isset($_POST["jcas_password_".$query_field]))

				{

					$query_value = md5(md5($_POST[$query_field]));

				}



				// Delete file when update

				if($query_type == "update")

				{

					if(isset($_POST["jcas_delete_".$query_field]))

					{

						@unlink("../".$cfg['upload_folder'].$_POST[$query_field]);

						@unlink("../".$cfg['upload_folder']."thumb_".$_POST[$query_field]);

						$query_value = "";

					}

				}



				$data_array[$query_field] = '"'.str_replace('"',"'",$query_value).'"';



			}

		}// end for each



		if(!$check_same_data)

		{

			$upload_process = true;

			// Start upload file

			foreach  ($_FILES as $file_field=>$file_value)

			{

				$file_name = $_FILES[$file_field]["name"];

				if($file_name)

				{

					// Get file's info

					$file_size = $_FILES[$file_field]["size"];

					$name = substr(strtolower($file_name),0,strlen($file_name)-4);

					$ext = substr(strtolower($file_name),-3);

					// Check file type

					if($cfg["allowed_file_type"] && !eregi($ext,$cfg["allowed_file_type"]))

					{

						$result .= message($lang["file_type_not_allowed"],'error');

						$upload_process = false;

						break;

					}

					// Check file size

					if($cfg["max_file_size"] && $file_size > $cfg["max_file_size"]*1024)

					{

						$result .= message($lang["file_size_not_allowed"],'error');

						$upload_process = false;

						break;

					}

					// Upload file to server

					$upload_file_name = replace_filename($name).'_'.$time.".".$ext;

					if (copy($_FILES[$file_field]['tmp_name'],'../'.$cfg['upload_folder'].'/'.$upload_file_name))

					{

						$file_array[$file_field] = '"'.$upload_file_name.'"';

							

						if($ext=="jpg" && $cfg["use_gd"])

						resize_jpg("../".$cfg['upload_folder']."/".$upload_file_name, "../".$cfg['upload_folder']."/"."thumb_".$upload_file_name,$cfg["max_thumb_width"],$cfg["max_thumb_height"]);

					}

					else

					{

						$upload_process = false;

						break;

					}

				}

			}



			// After upload, proceed to execute query

			if($upload_process)

			{

				// Insert query

				if($query_type=="insert" || $query_type=="copy")

				{

					$sql = 'INSERT IGNORE INTO '.$table.'(';

					foreach ($data_array as $query_field=>$query_value) $sql .= '`'.$query_field.'`, ';

					if($file_array) foreach ($file_array as $query_field=>$query_value) $sql .= '`'.$query_field.'`, ';

					$sql .= '`admin_id`,`sort`,`active`,`created_by`,`created_time`) VALUES (';

					foreach ($data_array as $query_field=>$query_value) $sql .= trim($query_value).', ';

					if($file_array) foreach ($file_array as $query_field=>$query_value) $sql .= trim($query_value).', ';

					$sql .= '"'.$admin_session['admin_id'].'","'.$_POST['jcas_sort'].'","'.$_POST['jcas_active'].'","'.$admin_session['admin_user'].'","'.mysql_datetime($time).'")';

				}

				// Update query

				else

				{

					$sql = 'UPDATE '.$table.' SET ';

					foreach ($data_array as $query_field=>$query_value) $sql .= '`'.$query_field.'`='.$query_value.', ';

					if($file_array) foreach ($file_array as $query_field=>$query_value) $sql .= '`'.$query_field.'`='.trim($query_value).', ';

					$sql .= (($_POST['jcas_updated_time'])?'`created_time`="'.mysql_datetime($time).'", ':'');

					$sql .= '`updated_time`="'.mysql_datetime($time).'", ';

					$sql .= '`updated_by`="'.$admin_session['admin_user'].'", ';

					$sql .= '`active`="'.$_POST['jcas_active'].'" WHERE `id`="'.$item_id.'"';

				}

				//print($sql);



				$query = $DB->query($sql);



				// Show result

				if($query)

				{

					if($query_type!="copy") $show_content = false;



					if($query_type=="insert")

					$result .= message_redirect($lang["data_inserted"],(($level=="cat")?$index_url."&p=add_cat":$index_url."&p=add_content"));

					elseif($query_type=="copy")

					$result .= message($lang["data_inserted"],'info');

					else

					$result .= message_redirect($lang["data_updated"],(($level=="cat")?$index_url.'&p=show&sp=show_cat':$index_url.'&p=show&sp=show_content&pg='.get("pg")));

					if ($mdl_cfg['parent_redirect'])

					$result = message_redirect($lang["data_updated"],str_replace (get('mdl'),$mdl_cfg['parent_redirect'],$index_url).'&p=show&sp=show_content&pg='.get("pg"));

					common_insert_action(ucfirst($query_type).' new '.$level,$table,$_GET['mdl']);
				}

				else

				{

					if($query_type=="insert" || $query_type=="copy")

					$result .= message($lang["inserted_fail"].'<br><font class="sql_error">'.$DB->error().'</font>','error');

					else

					$result .= message($lang["updated_fail"].'<br><font class="sql_error">'.$DB->error().'</font>','error');

				}

			}

			else

			{

				$result .= message($lang["uploaded_fail"],'error');

			}



		}// end if same data

		else

		{

			$result .= message(sprintf($lang["same_data_found"],$_POST[$check_same_data]),'error');

		}



		return $result;

	}



	###########################################################################################

	// Generate form adding category

	function add_cat()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session, $language;

		// Can not generate form

		if(!is_array($mdl_form))  die(message('Var $mdl_form is not an array with p=<font color="blue">'.$_GET['p'],'error'));

			

		// Generate form add category

		$this->form_cat = $mdl_form;



		$result = "";



		// Description

		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';



		// Action

		if($_POST["jcas_submit"]) $result .= $this->execute_db("insert",$_SESSION[get('mdl').'_cat_table'],"cat");

		if($_POST["jcas_copy"]) $result .= $this->execute_db("copy",$_SESSION[get('mdl').'_cat_table'],"cat");



		if($show_content)

		{

			// Jump and Search

			$result .= $this->draw_jump_search();



			// Tab

			$result .= $this->draw_tab();

			$result .= '<table width="100%"  border="0" cellspacing="0" cellpadding="0">

				<form name="frm_jcas" method="post" action="'.$index_url.'&p=add_cat" enctype="multipart/form-data">

				  <tr>

					 <td colspan="2" class="headtd"><a href="'.$index_url.'">'.$lang["manage_contents"].'</a> &#8250; '.$lang["add_new_category"].'</td>

				  </tr>';



			// Language list

			$result .= $this->draw_select_language();



			// Build fields

			foreach ($this->form_cat as $jcas_key=>$jcas_var)

			{

				if($jcas_key && $jcas_var)

				$result .= '<tr>

					<td width="25%" valign="top"  class="row1td"><b>'.$jcas_key.'</b></td>

					<td width="75%"  class="row2td">'.$jcas_var.'</td>

					</tr>';

			}

			if($_SESSION[get('mdl').'_cat_table'] && $mdl_cfg['parent_select'])

			{

				$result .= '<tr><td class="row1td" valign="top"><b>'.$lang["parent_category"].'</b></td><td class="row2td">';

				$result .= $this->draw_select_cat($_SESSION[get('mdl').'_cat_table'],'parent_id','',2,0);

				$result .= '</td></tr>';

			}

			$result .=	'<tr >

				<td valign="top" class="row1td"><b>'.$lang["active"].'</b></td>

				<td class="row2td"><input type="checkbox" name="jcas_active" class="box" value="1" checked="true" /></td>

				</tr>';			

			$result .= '<tr >

				 <td colspan="2" align="center" class="row2td">

					<input type="submit" name="jcas_submit" class="btn_bg btn_insert" value="'.$lang["btn_insert"].'">

					<input type="submit" name="jcas_copy" class="btn_bg btn_copy" value="'.$lang["btn_copy"].'">

					</td>

				</tr>

			 </form>

			</table>';

		}// end show_content

		echo $result;

	}



	###########################################################################################

	// Generate form editing category

	function edit_cat()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		// Can not generate form

		if(!is_array($mdl_form))  die(message('Var $mdl_form is not an array with p=<font color="blue">'.$_GET['p'],'error'));

			

		// Generate form edit category

		$this->form_cat =  $mdl_form;

			

		$result = "";

		// Desciption

		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';



		// Action update

		if($_POST["jcas_submit"])

		{

			if(!$cfg["editing_same"])

			{

				// Empty editing field

				$DB->query('UPDATE '.$_SESSION[get('mdl').'_cat_table'].' SET editing_time="", editing_by="" WHERE id="'.$_GET['cat_id'].'"');

			}

			$result .= $this->execute_db("update",$_SESSION[get('mdl').'_cat_table'],"cat");

		}

		// Action delete

		if($_POST["jcas_delete"])

		{

			$DB->query('DELETE FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE id="'.$_GET['cat_id'].'"');

			$result .= message_redirect($lang['data_deleted'],$index_url.'&p=show&sp=show_cat');

			$show_content = false;

		}



		// Can not find specified category

		if(!$cat && !$_POST['jcas_delete'])

		{

			$result .= message_redirect($lang["no_requested_data"],$index_url.'&p=show&sp=show_cat');

			$show_content = false;

		}



		if($show_content)

		{

			// Get previous record's id



			// Get next record's id



			// Check if editing same item

			$result .= common_same_editing($_SESSION[get('mdl').'_cat_table'],'id',$_GET['cat_id']);



			// Jump and Search

			$result .= $this->draw_jump_search();



			// Tab

			$result .= $this->draw_tab();



			$result .= '<table width="100%"  border="0" cellspacing="0" cellpadding="0" >

					<form name="frm_jcas" method="post" action="'.$index_url.'&p=edit_cat&cat_id='.$_GET['cat_id'].'" enctype="multipart/form-data">

					  <tr>

						 <td colspan="2" class="headtd"><a href="'.$index_url.'&p=show&sp=show_cat">'.$lang["manage_contents"].'</a> &#8250; '.$lang["edit_category"].'</td>

					  </tr>';

			// Language list

			$result .= $this->draw_select_language();



			// Build fields

			foreach ($this->form_cat as $jcas_key=>$jcas_var)

			{

				if($jcas_key && $jcas_var)

				$result .= '<tr >

				<td width="25%" valign="top" class="row1td"><b>'.$jcas_key.'</b></td>

				<td width="75%" class="row2td">'.$jcas_var.'</td>

				</tr>';

			}

			if($_SESSION[get('mdl').'_cat_table'] && $mdl_cfg['parent_select'])

			{

				$result .= '<tr ><td class="row1td"><b>'.$lang["parent_category"].'</b></td><td class="row2td">';

				$result .= $this->draw_select_cat($_SESSION[get('mdl').'_cat_table'],'parent_id','',2,0);

				$result .= '</td></tr>';

			}

			$result .= '<tr >

				<td valign="top" class="row1td"><b>'.$lang["updated_time"].'</b></td>

				<td class="row2td"><input type="checkbox" name="jcas_updated_time" class="box" value="1" /></td>

				</tr>

				<tr > 

				<td valign="top" class="row1td"><b>'.$lang["active"].'</b></td>

				<td class="row2td"><input type="checkbox" name="jcas_active" class="box" value="1" '.(($cat['active'])?'checked="true"':'').' /></td>

				</tr>

				<tr >

						 <td colspan="2" align="center" class="row2td">

							<input type="submit" name="jcas_submit" class="btn_bg btn_update" value="'.$lang["btn_update"].'">

							<input name="reset" type="reset" class="btn_bg btn_reset" value="'.$lang["btn_reset"].'">

							<input type="submit" name="jcas_delete"  class="btn_bg btn_delete" value="'.$lang["btn_delete"].'" onClick="return confirm(\''.$lang['js_confirm_delete'].'\')">

						</td>

						</tr>

					 </form>

					</table>';

		}

		echo $result;

	}



	###########################################################################################

	// Generate form adding content

	function add_content()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		// Can not generate form

		if(!is_array($mdl_form))  die(message('Var $mdl_form is not an array with p=<font color="blue">'.$_GET['p'],'error'));

			

		$this->form_add =  $mdl_form;



		$result = "";

		// Description

		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';



		// Action

		if($_POST["jcas_submit"]) $result .= $this->execute_db("insert",$tbl['content'],"content");

		if($_POST["jcas_copy"]) $result .= $this->execute_db("copy",$tbl['content'],"content");



		// Check valid variables

		if($show_content)

		{

			// Jump and search

			//	$result .= $this->draw_jump_search();



			// Tab

			$result .= $this->draw_tab();



			// JS validate

			if($mdl_cfg['required_fields']) $result .= js_validate($mdl_cfg['required_fields'],'frm_jcas');



			$result .= '<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">

			<form name="frm_jcas" method="post" action="'.$index_url.'&p=add_content&cat_id='.get('cat_id').'" enctype="multipart/form-data" '.(($mdl_cfg['required_fields'])?'onSubmit="return validate_frm_jcas()"':'').'>

			<tr> 

			<td colspan="2" class="headtd">'.(($mdl_cfg['head_title'])?$mdl_cfg['head_title']:'<a href="'.$index_url.'">'.$lang["manage_contents"].'</a> &#8250; '.$lang["add_new_content"]).'</td>

			</tr>';



			// Language list

			$result .= $this->draw_select_language();



			// Data for form (in row)

			foreach ($this->form_add as $jcas_key=>$jcas_var)

			{

				if($jcas_key && $jcas_var)

				$result .= '<tr>

				<td width="25%" valign="top" class="row1td"><b>'.$jcas_key.'</b></td>

				<td width="75%" class="row2td">'.$jcas_var.'</td>

				</tr>';

			}

			$result .=	'<tr >

				<td valign="top" class="row1td"><b>'.$lang["active"].'</b></td>

				<td class="row2td"><input type="checkbox" name="jcas_active" class="box" value="1" checked="true" /></td>

				</tr>';						

			$result .= '<tr >

			<td colspan="2" align="center" class="row2td">

			<input type="submit" name="jcas_submit" class="btn_bg btn_insert" value="'.$lang["btn_insert"].'">

			<input type="submit" name="jcas_copy" class="btn_bg btn_copy" value="'.$lang["btn_copy"].'">

			</td>

			</tr>

			</form>

			</table>';



			if($cfg["enable_hotkeys"])

			{

				// Hotkeys & script

				$result .= '<div id="hotkeys">

					<div class="hotkeys_title">'.$lang['hotkeys'].'</div>

					<div class="hotkeys_content">'.$lang['hotkeys_content'].'</div>

				</div>';

				$result .= '<script src="js/shortcuts.js" language="JavaScript" type="text/javascript"></script>';

				$result .= '<script language="JavaScript">

				document.getElementById(\'title\').focus();

				

				shortcut.add("Ctrl+S",function() {

									document.frm_jcas.jcas_submit.value = \'save\';

									document.frm_jcas.submit();

				}); 

				

				shortcut.add("Ctrl+Shift+S",function() {

									document.frm_jcas.jcas_submit.value = \'save_next\';

									document.frm_jcas.submit();

				}); 

				

				

				shortcut.add("Ctrl+R",function() {

									document.frm_jcas.reset();

				}); 

				

				shortcut.add("Ctrl+C",function() {

									window.location=\''.$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id'].'\';

				}); 

				

				

				shortcut.add("Ctrl+,",function() {

									'.(($previous_link)?'window.location=\''.$previous_link.'\';':'alert(\''.$lang['no_older_record'].'\');').'					

				});

				

				shortcut.add("Ctrl+.",function() {

									'.(($next_link)?'window.location=\''.$next_link.'\';':'alert(\''.$lang['no_newer_record'].'\');').'					

				});

				</script>';

			}

		}

		// Print all

		echo $result;

	}



	###########################################################################################

	// Generate form editing category

	function edit_content()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		// Can not generate form

		if(!is_array($mdl_form))  die(message('Var $mdl_form is not an array with p=<font color="blue">'.$_GET['p'],'error'));



		$this->form_edit = $mdl_form;

		$result = "";

		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';



		// Action update

		if($_POST["jcas_submit"] || ($_POST["jcas_action"]=='save'))

		{

			if(!$cfg["editing_same"])

			{

				// Empty editing field

				$DB->query('UPDATE '.$tbl['content'].' SET editing_time="", editing_by="" WHERE id="'.$_GET['id'].'"');

			}

			$result .= $this->execute_db("update",$tbl['content'],"content");

		}

		// Action delete

		if($_POST["jcas_delete"] || ($_POST["jcas_action"]=='delete'))

		{

			$DB->query('DELETE FROM '.$tbl['content'].' WHERE id="'.$_GET['id'].'"');

			$result .= message_redirect($lang['data_deleted'],$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id']);

			$show_content = false;

		}



		// Can not find content

		if(!$content && !$_POST["jcas_delete"])

		{

			$show_content = false;

			$result .= message_redirect($lang["no_requested_data"],$index_url.'&p=show');

		}





		if($show_content)

		{

			/*$sql_order = $_SESSION[get('mdl').'_content_sort_by'].' '.$_SESSION[get('mdl').'_content_sort_order'];
			 if ($sql_order!==' ') $sql_order.=',';
			 $sql_order.=' created_time DESC';*/

			// Get previous record

			//			$previous = $DB->fetch_array($DB->query('SELECT id,created_time FROM '.$tbl["content"].' WHERE id > '.$_GET['id'].' ORDER BY '.$sql_order.' LIMIT 0,1')); // created_time < "'.$content['created_time'].'"

			//			if($previous) $previous_link = $index_url.'&p='.$_GET['p'].'&sp='.$_GET['sp'].'&cat_id='.$_GET['cat_id'].'&id='.$previous['id'];



			// Get next record

			//			$next = $DB->fetch_array($DB->query('SELECT id,created_time FROM '.$tbl["content"].' WHERE id > '.$_GET['id'].' ORDER BY '.$sql_order.' LIMIT 0,1')); // created_time > "'.$content['created_time'].'"

			//			if($next) $next_link = $index_url.'&p='.$_GET['p'].'&sp='.$_GET['sp'].'&cat_id='.$_GET['cat_id'].'&id='.$next['id'];

			// Check if editing same item

			$result .= common_same_editing($tbl["content"],'id',$_GET['id']);

			// JS validate

			if($mdl_cfg['required_fields']) $result .= js_validate($mdl_cfg['required_fields'],'frm_jcas');



			// Head url

			if ($content['cat_id'])

			$head_url = '&#8250; <a href="'.$index_url.'&p=show&sp=show_content&cat_id='.$content['cat_id'].'&pg='.$_GET["pg"].'">'.$cat['title'].'</a>';

			else $head_url = "";



			// Jump and Search

			//$result .= $this->draw_jump_search();



			$result .= $this->draw_tab();



			$result .= '<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">

			<form name="frm_jcas" method="post" action="'.$index_url.'&p=edit_content&cat_id='.$_GET['cat_id'].'&id='.$_GET['id'].'&pg='.$_GET["pg"].'" enctype="multipart/form-data" '.(($mdl_cfg['required_fields'])?'onSubmit="return validate_frm_jcas()"':'').'>

			<tr> 

			<td colspan="2" class="headtd">'.(($mdl_cfg['head_title'])?$mdl_cfg['head_title']:'<a href="'.$index_url.'&p=show&sp=show_cat">'.$lang["manage_contents"].'</a> '.$head_url.' &#8250; '.$lang["edit_content"]).'</td>

			</tr>';



			// Language list

			$result .= $this->draw_select_language();



			// Data for form (in row)

			foreach ($this->form_edit as $jcas_key=>$jcas_var)

			{
				if($jcas_key && $jcas_var)

				$result .= '<tr >

					<td width="25%" valign="top" class="row1td"><b>'.$jcas_key.'</b></td>

					<td width="75%" class="row2td">'.$jcas_var.'</td>

					</tr>';

			}
			if(!$mdl_cfg['parent_redirect']):
			$result .=	'<tr >

					<td valign="top" class="row1td"><b>'.$lang["updated_time"].'</b></td>
	
					<td class="row2td"><input type="checkbox" name="jcas_updated_time" class="box" value="1" /></td>
	
					</tr>
	
					<tr > 
	
					<td valign="top" class="row1td"><b>'.$lang["active"].'</b></td>
	
					<td class="row2td"><input type="checkbox" name="jcas_active" class="box" value="1" '.(($content['active'])?'checked="true"':'').' /></td>
	
					</tr>';		
			endif;
			$result .= '<tr >

			<td colspan="2" align="center" class="row2td">

			<input type="submit" name="jcas_submit" class="btn_bg btn_update" value="'.$lang["btn_update"].'">

			<!--<input type="submit" name="jcas_submit_next" class="btn_bg btn_save_next" value="'.$lang["btn_save_next_record"].'">-->

			<input type="reset" name="reset" class="btn_bg btn_reset" value="'.$lang["btn_reset"].'">

			<input type="submit" name="jcas_delete"  class="btn_bg btn_delete" value="'.$lang["btn_delete"].'" onClick="return confirm(\''.$lang['js_confirm_delete'].'\')">

			<!--<strong>&laquo;</strong> <a href="'.$previous_link.'#" '.((!$previous)?'onClick="alert(\''.$lang['no_older_record'].'\'); return false;"':'').'>Tin cũ hơn</a> |

			<a href="'.$next_link.'#" '.((!$next)?'onClick="alert(\''.$lang['no_newer_record'].'\'); return false;"':'').'>Tin mới hơn</a> <strong>&raquo;</strong>-->

			<!--<input type="button" class="btn_bg_small btn_previous" value="'.$lang["btn_previous_record"].'">

			<input type="button" class="btn_bg_small btn_next" value="'.$lang["btn_next_record"].'">-->

			</td>

			</tr>';



			$result .= '

			<input type="hidden" name="jcas_action" value="" />

			</form>

			</table>';



			if($cfg["enable_hotkeys"])

			{

				// Hotkeys & script

				$result .= '<div id="hotkeys">

					<div class="hotkeys_title">'.$lang['hotkeys'].'</div>

					<div class="hotkeys_content">'.$lang['hotkeys_content'].'</div>

				</div>';

				$result .= '<script src="js/shortcuts.js" language="JavaScript" type="text/javascript"></script>';

				$result .= '<script language="JavaScript">

				document.getElementById(\'title\').focus();

				

				shortcut.add("Ctrl+S",function() {

									document.frm_jcas.jcas_action.value = \'save\';

									document.frm_jcas.submit();

				}); 

				

				shortcut.add("Ctrl+Shift+S",function() {

									document.frm_jcas.jcas_action.value = \'save_next\';

									document.frm_jcas.submit();

				}); 

				

				

				shortcut.add("Ctrl+R",function() {

									document.frm_jcas.reset();

				}); 

				

				shortcut.add("Ctrl+C",function() {

									window.location=\''.$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id'].'\';

				}); 

				

				shortcut.add("Ctrl+D",function() {

									if(confirm(\''.$lang['js_confirm_delete'].'\'))

									{

										document.frm_jcas.jcas_action.value = \'delete\';

										document.frm_jcas.submit();

									}

									else return false;

				});

				

				shortcut.add("Ctrl+,",function() {

									'.(($previous_link)?'window.location=\''.$previous_link.'\';':'alert(\''.$lang['no_older_record'].'\');').'					

				});

				

				shortcut.add("Ctrl+.",function() {

									'.(($next_link)?'window.location=\''.$next_link.'\';':'alert(\''.$lang['no_newer_record'].'\');').'					

				});

				</script>';

			}

		}

		// Print all

		echo $result;

	}



	###########################################################################################

	// Generate form viewing category

	function view_content()

	{

		global $DB,$time,$tbl,$cfg,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session;

		if(!is_array($mdl_form))

		die(message('Var $mdl_form is not an array with p=<font color="blue">'.$_GET['p'],'error'));

			

		$this->form_view = $mdl_form;

		$result = "";



		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';



		// Can not find content

		if(!$content)

		{

			$show_content = false;

			$result .= message_redirect($lang["no_requested_data"],$index_url.'&p=show');

		}



		if($show_content)

		{

			// Head url

			if ($content['cat_id'])

			$head_url = '&#8250; <a href="'.$index_url.'&p=show&sp=show_content&cat_id='.$content['cat_id'].'&pg='.$_GET["pg"].'">'.$cat['title'].'</a>';

			else $head_url = "";



			// Jump and Search

			$result .= $this->draw_jump_search();

			// Tab

			$result .= $this->draw_tab();



			$result .= '<table width="100%" border="0" cellspacing="0" cellpadding="0"  align="center">

					<tr > 

					<td colspan="2" class="headtd"><a href="'.$index_url.'&p=show&sp=show_cat">'.$lang["manage_contents"].'</a> '.$head_url.' &#8250; '.$lang["view_content"].'</td>

					</tr>';



			// Data for form (in row)

			foreach ($this->form_view as $jcas_key=>$jcas_var)

			{

				$result .= '<tr >

				<td width="25%" valign="top" class="row1td"><b>'.$jcas_key.'</b></td>

				<td width="75%" class="datatd" bgcolor="#FFFFFF">'.$jcas_var.'</td>

				</tr>';

			}

			$result .= '<tr >

				<td  valign="top" class="row1td">&nbsp;</td>

				<td  class="datatd" bgcolor="#FFFFFF"><input type="button" onClick="window.location=\''.$index_url.'&p=show&sp=show_cat\'" class="button" value="'.$lang["btn_back"].'"></td>

				</tr>';

			$result .= '</table>';

		}

		// Print all

		echo $result;

	}



	###########################################################################################

	// Generate form search content

	function search_content()

	{
		$_GET["p"] = 'show';
		$_GET["sp"] = 'show_content';
		//		$show_content = true;

		$this->show();

	}



	###########################################################################################

	// Generate form showing category & content

	function show()

	{

		global $DB,$time,$tbl,$cfg,$database,$lang,$mdl_form,$mdl_cfg,$content,$cat,$index_url,$show_content,$module,$sub_module,$admin_session,$mdl_sql;

		$result = "";

		// Show contents if there is no cat table

		if(!$tbl['cat']) $_GET["sp"] = 'show_content';



		// Cat options

		if($_GET['cat_option'])

		{

			if($_GET['cat_option'] == 'default')

			{

				$_SESSION[get('mdl').'_cat_option'] = 'default';

				$_SESSION[get('mdl').'_cat_table'] = $tbl['cat'];

				$_SESSION[get('mdl').'_cat_field'] = 'cat_id';

			}

			else

			{

				$_SESSION[get('mdl').'_cat_option'] = $_GET['cat_option'];

				$_SESSION[get('mdl').'_cat_table'] = $_GET['cat_table'];

				$_SESSION[get('mdl').'_cat_field'] = $_GET['cat_field'];

			}

		}

		else

		{

			if(!$_SESSION[get('mdl').'_cat_table'])

			{

				$_SESSION[get('mdl').'_cat_option'] = 'default';

				$_SESSION[get('mdl').'_cat_table'] = $tbl['cat'];

				$_SESSION[get('mdl').'_cat_field'] = 'cat_id';

			}

		}





		// Content options

		if($_GET['content_option'])

		{

			if($_GET['content_option'] == 'default')

			{

				$_SESSION[get('mdl').'_content_option'] = 'default';

				$_SESSION[get('mdl').'_content_field'] = false;

				$_SESSION[get('mdl').'_content_value'] = false;

			}

			else

			{

				$_SESSION[get('mdl').'_content_option'] = $_GET['content_option'];

				$_SESSION[get('mdl').'_content_field'] = $_GET['content_field'];

				$_SESSION[get('mdl').'_content_value'] = $_GET['content_value'];

			}

		}

		else

		{

			if(!$_SESSION[get('mdl').'_content_field'])

			{

				$_SESSION[get('mdl').'_content_option'] = 'default';

				$_SESSION[get('mdl').'_content_field'] = false;

				$_SESSION[get('mdl').'_content_value'] = false;

			}

		}





		// Cat sort options

		if(!$_SESSION[get('mdl').'_cat_sort_by'])

		$_SESSION[get('mdl').'_cat_sort_by'] = 'sort';

			

		if(!$_SESSION[get('mdl').'_cat_sort_order'])

		$_SESSION[get('mdl').'_cat_sort_order'] = 'ASC';





		// Content Sort options

		if($_POST['sort_by'])

		{

			if($_POST['sort_by'] == 'default')

			{

				$_SESSION[get('mdl').'_content_sort_by'] = 'sort';

				$_SESSION[get('mdl').'_content_sort_order'] = 'ASC';

			}

			else

			{

				$_SESSION[get('mdl').'_content_sort_by'] = $_POST['sort_by'];

				$_SESSION[get('mdl').'_content_sort_order'] = $_POST['sort_order'];

			}

		}

		else

		{

			if(!$_SESSION[get('mdl').'_content_sort_by'])

			{

				$_SESSION[get('mdl').'_content_sort_by'] = 'sort';

				$_SESSION[get('mdl').'_content_sort_order'] = 'ASC';

			}

		}



		// Description

		if($mdl_cfg['module_description']) $result .= '<div style="background-color:#FFFFFF; padding:5px" class="datatd">'.$mdl_cfg['module_description'].'</div>';

		switch ($_GET["sp"])

		{

			case "show_cat":

			default:

				// Delete 1 cat

				if($_GET['act'] == "delete" && $_GET['cat_id'])

				{

					if($tbl["content"]) $DB->query('DELETE FROM '.$tbl["content"].' WHERE '.$_SESSION[get('mdl').'_cat_field'].'="'.$_GET['cat_id'].'"');

					if ($mdl_cfg['parent_select']){
						$q_delete1 = $DB->query('DELETE FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE parent_id="'.$_GET['cat_id'].'"');
					}else{
						$q_delete1 =true;
					}

					$q_delete2 = $DB->query('DELETE FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE id="'.$_GET['cat_id'].'"');

					if($q_delete1 && $q_delete2)

					{

						$result .= message($lang["data_deleted"],'info');

						common_insert_action('Delete cat',$_SESSION[get('mdl').'_cat_table'],$_GET['mdl']);

					}

					else $result .= message($lang["deleted_fail"],'error');

				}



				// Delete selected cat

				if(post("action") == "delete_selected" && $_POST['cat_id'])

				{

					foreach ($_POST['cat_id'] as $c_id)

					{

						if($tbl["content"]) $DB->query('DELETE FROM '.$tbl["content"].' WHERE '.$_SESSION[get('mdl').'_cat_field'].'='.$c_id);

						$q_delete1 = $DB->query('DELETE FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE parent_id='.$c_id);

						$q_delete2 = $DB->query('DELETE FROM '.$_SESSION[get('mdl').'_cat_table'].' WHERE id='.$c_id);

						if(!$q_delete1 || !$q_delete2) break;

					}

					if($q_delete1 && $q_delete2)

					{

						$result .= message($lang["data_deleted"],'info');

						common_insert_action('Delete selected cats',$_SESSION[get('mdl').'_cat_table'],$_GET['mdl']);

					}

					else $result .= message($lang["deleted_fail"],'error');

				}



				// Move selected cat

				if($_POST["move"] && $_POST['cat_id'] && $_POST['parent_id'])

				{

					foreach ($_POST['cat_id'] as $c_id)

					{

						if($c_id != $_POST['parent_id'])

						$q_update = $DB->query('UPDATE '.$_SESSION[get('mdl').'_cat_table'].' SET parent_id='.$_POST['parent_id'].' WHERE id='.$c_id);

						else

						{

							$result .= message($lang["duplicate_moved_id"],'error');

							$q_update = false;

						}

						if(!$q_update) break;

					}

					if($q_update)

					{

						$result .= message($lang["data_updated"],'info');

						common_insert_action('Move selected cats',$_SESSION[get('mdl').'_cat_table'],$_GET['mdl']);

					}

					else $result .= message($lang["updated_fail"],'error');

				}

				// Update sort

				$result .= common_update_sort($_SESSION[get('mdl').'_cat_table'],'id','sort');

				// Set value

				$result .= common_set_value($_SESSION[get('mdl').'_cat_table'],'id');

				// Activate selected

				$result .= common_activate_selected($_SESSION[get('mdl').'_cat_table'],'id','active');

				// Deactivate selected

				$result .= common_deactivate_selected($_SESSION[get('mdl').'_cat_table'],'id','active');



				if($show_content)

				{

					// search

					if($mdl_cfg['search_fields'])

					$result .= '<div align=right>'.$this->draw_form_search().'</div>';

					else $result .= '<br/>';



					// Tab

					$result .= $this->draw_tab();

					$result .='<table width="100%"  border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">

					<form name="frm_show" method="post" action="'.$index_url.'&p=show&sp=show_cat">

							  <tr>

								 <td colspan="10" class="headtd">

								 	<table width="100%" cellpadding=0 cellspacing=0 border=0>

									<tr>

									<td style="color:#FFFFFF; font-weight:bold">'.$lang["manage_contents"].'</td>

									<td align=right>'.$this->draw_options('cat').'</td>

									</tr>

									</table>

								 </td>

							  </tr>

							  <tr align="center">

								 <td width="30" class="subheadtd">'.$lang["order"].'</td>

								 <td width="55%" class="subheadtd">'.$lang["category"].'</td>

								 <td width="5%" class="subheadtd">'.$lang["sort"].'</td>

								 <td width="15%" class="subheadtd">'.$lang["added_date"].'</td>

								 <td width="5%" class="subheadtd">'.$lang["active"].'</td>

								 <td width="10%" class="subheadtd"><input type="checkbox" name="all_id" class="box" value="all" onClick="set_all_cb(\'frm_show\',\'cat_id[]\',\'all_id\');" title="'.$lang['checkbox_all'].'"></td>

							  </tr>';



					// Select cat

					$q_cat = $DB->query((($mdl_sql['show_cat'])?$mdl_sql['show_cat']:'SELECT cat.* '.(($tbl["content"])?',COUNT(content.id) AS total_content':'').' FROM '.$_SESSION[get('mdl').'_cat_table'].' AS cat '.(($tbl["content"])?' LEFT JOIN '.$tbl["content"].' AS content':'').' '.(($tbl["content"])?' ON  content.cat_id=cat.id':'').' WHERE cat.id>0 '.(($_SESSION['admin_show_lang_id'])?'AND cat.lang_id='.$_SESSION['admin_show_lang_id']:'').' GROUP BY cat.id ORDER BY cat.'.$_SESSION[get('mdl').'_cat_sort_by'].' '.$_SESSION[get('mdl').'_cat_sort_order'].', cat.created_time DESC '));



					$total_cat = $DB->num_rows($q_cat);



					if($total_cat)

					{

						// List all cat variables

						for($x=0;$x<$total_cat;$x++)

						{

							$cat[$x] = $DB->result_array($q_cat,$x,"id,lang_id,sort,parent_id,name,active,created_by,created_time,updated_by,updated_time".(($tbl["content"])?',total_content':''));

							$cat_title[$x] = common_status_title($cat[$x]['created_by'], timestamp($cat[$x]['created_time']), $cat[$x]['updated_by'], timestamp($cat[$x]['updated_time']));

							$row_color[$x] = (!$cat[$x]['active'])?'bgcolor="#EEEEEE"':'';

						}



						// CAT LEVEL 1

						$cat1_no = 0;

						for($x1=0;$x1<$total_cat;$x1++)

						{

							$cat1_exist = false;

							if($cat[$x1]['parent_id'] == 0)

							{

								$cat1_no += 1;

								$result .= '<tr onMouseOver="rollon(this);" onMouseOut="rolloff(this);" '.$row_color[$x1].'>

								<td class="datatd" align="right" style="color:red" >'.$cat1_no.'</td>

								<td class="datatd"> <a href="'.$index_url.(($tbl["content"])?'&p=show&sp=show_content&cat_id='.$cat[$x1]['id']:'&p=edit_cat&cat_id='.$cat[$x1]['id']).'" title="'.$cat_title[$x1].'">'.$cat[$x1]['name'].'</a> '.(($tbl["content"])?'<font class="grey10">('.number($cat[$x1]['total_content']).')</font>':'').' '.html_show_flag($cat[$x1]['lang_id']).'</td>

								<td align="center" class="datatd">'.html_input_sort('sort',$cat[$x1]['id'],$cat[$x1]['sort']).'</td>

								<td align="center" class="datatd">'.show_date($cfg["date_format"],timestamp($cat[$x1]['created_time'])).'</td>

								<td align="center" class="datatd">'.html_yes_no($cat[$x1]['active'],'active',$index_url.'&p=show&sp=show_cat&cat_id='.$cat[$x1]['id']).'</td>

								<td align="center" class="datatd">

									'.html_icon_edit($index_url.'&p=edit_cat&cat_id='.$cat[$x1]['id']).'

									'.html_icon_delete($index_url.'&p=show&sp=show_cat&act=delete&cat_id='.$cat[$x1]['id']).'

									'.html_input_checkbox('cat_id',$cat[$x1]['id']).'

								</td>

								</tr>';

								$cat1_exist = true;

							}



							if($cat1_exist)

							{

								// CAT LEVEL 2

								$cat2_no = 0;

								for($x2=0;$x2<$total_cat;$x2++)

								{

									$cat2_exist = false;

									if($cat[$x2]['parent_id'] == $cat[$x1]['id'])

									{

										$cat2_no += 1;

										$result .= '<tr onMouseOver="rollon(this);" onMouseOut="rolloff(this);" '.$row_color[$x2].'>

										<td class="datatd" align="right" style="color:blue" >'.$cat1_no.'.'.$cat2_no.'</td>

										<td class="datatd"><img src="images/arrow.gif">  <a href="'.$index_url.(($tbl["content"])?'&p=show&sp=show_content&cat_id='.$cat[$x2]['id']:'&p=edit_cat&cat_id='.$cat[$x2]['id']).'" title="'.$cat_title[$x2].'">'.$cat[$x2]['name'].'</a> '.(($tbl["content"])?'<font class="grey10">('.number($cat[$x2]['total_content']).')</font>':'').' '.html_show_flag($cat[$x2]['lang_id']).'</td>

										<td align="center" class="datatd">'.html_input_sort('sort',$cat[$x2]['id'],$cat[$x2]['sort'],'blue').'</td>

										<td align="center" class="datatd">'.show_date($cfg["date_format"],timestamp($cat[$x2]['created_time'])).'</td>

										<td align="center" class="datatd">'.html_yes_no($cat[$x2]['active'],'active',$index_url.'&p=show&sp=show_cat&cat_id='.$cat[$x2]['id']).'</td>

										<td align="center" class="datatd">

											'.html_icon_edit($index_url.'&p=edit_cat&cat_id='.$cat[$x2]['id']).'

											'.html_icon_delete($index_url.'&p=show&sp=show_cat&act=delete&cat_id='.$cat[$x2]['id']).'

											'.html_input_checkbox('cat_id',$cat[$x2]['id']).'

										</td>

										</tr>';

										$cat2_exist = true;

									}



									if($cat2_exist)

									{

										// CAT LEVEL 3

										$cat3_no = 0;

										for($x3=0;$x3<$total_cat;$x3++)

										{

											if($cat[$x3]['parent_id'] == $cat[$x2]['id'])

											{

												$cat3_no += 1;

												$result .= '<tr onMouseOver="rollon(this);" onMouseOut="rolloff(this);" '.$row_color[$x3].'>

												<td class="datatd" align="right" >'.$cat1_no.'.'.$cat2_no.'.'.$cat3_no.'</td>

												<td class="datatd"><img src="images/arrow.gif" style="margin-left:18px"> <a href="'.$index_url.(($tbl["content"])?'&p=show&sp=show_content&cat_id='.$cat[$x3]['id']:'&p=edit_cat&cat_id='.$cat[$x3]['id']).'" title="'.$cat_title[$x3].'">'.$cat[$x3]['name'].'</a> '.(($tbl["content"])?'<font class="grey10">('.number($cat[$x3]['total_content']).')</font>':'').' '.html_show_flag($cat[$x3]['lang_id']).'</td>

												<td align="center" class="datatd">'.html_input_sort('sort',$cat[$x3]['id'],$cat[$x3]['sort'],'black').'</td>

												<td align="center" class="datatd">'.show_date($cfg["date_format"],timestamp($cat[$x3]['created_time'])).'</td>

												<td align="center" class="datatd">'.html_yes_no($cat[$x3]['active'],'active',$index_url.'&p=show&sp=show_cat&cat_id='.$cat[$x3]['id']).'</td>

												<td align="center" class="datatd">

													'.html_icon_edit($index_url.'&p=edit_cat&cat_id='.$cat[$x3]['id']).'

													'.html_icon_delete($index_url.'&p=show&sp=show_cat&act=delete&cat_id='.$cat[$x3]['id']).'

													'.html_input_checkbox('cat_id',$cat[$x3]['id']).'

												</td>

												</tr>';

											}

										}// end for L3

									} // end if L2

								} // end for L2

							} // end if L1

						}// end for L1

					}

					else $result .= '<tr ><td colspan="10" align="center" class="datatd">'.message($lang["no_requested_data"],'info').'</td></tr>';

					$result .= '<tr>

					<td colspan="10" align="right">

					 <table width="100%"  border="0" cellpadding="0" cellspacing="0">

					  <tr align="center" >

					  	<td width="100%" align="right" class="row1td">'. ($mdl_cfg['disable_move']?'':$this->draw_form_move($_SESSION[get('mdl').'_cat_table'],'parent_id',2) ).'</td>

						 <td width="10%" class="row1td"><input type="submit" name="update_sort" value="'.$lang["update_sort"].'" class="button"></td>

						 <td width="10%" class="row1td">'.common_action_list().'</td>

					  </tr>

					</table>

					</td></tr>';

					$result .= '</form></table>';

				}

				break;

					

					

			case "show_content":

				$this->tpl = html_get(get_html_content('_templates/'.$_GET["mdl"].'.html'),"table");

				$this->row_tpl = html_get($this->tpl,"row");

				$this->row_result = "";



				// Update sort

				$result .= common_update_sort($tbl["content"],'id','sort');

				// Set value

				$result .= common_set_value($tbl["content"],'id');

				// Delete 1 item

				$result .= common_delete($tbl["content"],'id');

				// Delete selected

				$result .= common_delete_selected($tbl["content"],'id');

				// Activate selected

				$result .= common_activate_selected($tbl["content"],'id','active');

				// De-activate selected

				$result .= common_deactivate_selected($tbl["content"],'id','active');


				// Move selected items

				if($_POST["move"] && $_POST["id"] && $_POST['cat_id'])

				{

					foreach ($_POST["id"] as $c_id)

					{

						$q_update = $DB->query('UPDATE '.$tbl["content"].' SET '.$_SESSION[get('mdl').'_cat_field'].'='.$_POST['cat_id'].' WHERE id='.$c_id);

						if(!$q_update) break;

					}

					if($q_update)

					{

						$result .= message($lang["data_updated"],'info');

						common_insert_action('Move',$tbl["content"],$_GET['mdl']);

					}

					else $result .= message($lang["updated_fail"],'error');

				}



				if($show_content)

				{

					$sql_cat = ($_GET['cat_id'])?' and '.$mdl_cfg['tbl_alias'].$_SESSION[get('mdl').'_cat_field'].'='.$_GET['cat_id']:' and '.$mdl_cfg['tbl_alias'].'id>0';

					$sql_active = ($_SESSION[get('mdl').'_content_field'])?' AND '.$mdl_cfg['tbl_alias'].$_SESSION[get('mdl').'_content_field'].'='.$_SESSION[get('mdl').'_content_value']:'';

					$sql_lang = ($_SESSION['admin_show_lang_id'])?' AND lang_id='.$_SESSION['admin_show_lang_id']:'';

					$sql_order = ' ORDER BY '.$mdl_cfg['custom_order'].' '.$mdl_cfg['tbl_alias'].$_SESSION[get('mdl').'_content_sort_by'].' '.$_SESSION[get('mdl').'_content_sort_order'].', '.$mdl_cfg['tbl_alias'].'created_time DESC';

					$sql_search = (get("keyword"))?' AND '.$mdl_cfg['tbl_alias'].'`'.get("search_field").'` LIKE "%'.str_replace(" ","%",get("keyword")).'%"':'';

					$sql_content = $mdl_sql['show_content']?$mdl_sql['show_content']:'SELECT SQL_CALC_FOUND_ROWS * FROM '.$tbl["content"].' WHERE 1';


					$sql_content .=$sql_cat.' '.$sql_lang.' '.$sql_active.' '.$sql_search.' '.$sql_order;

					$sql_content.=' LIMIT '.(get('pg')-1)*$mdl_cfg["content_per_page"].','.$mdl_cfg["content_per_page"];

					$q_content = $DB->query($sql_content);

					$num_content = $DB->num_rows($q_content);

					if($num_content)

					{

						while ($row = $DB->fetch_assoc($q_content)):
							
							
						foreach ($row as $key=>$val):

						$row_data[$key] = $val;

						if ( is_numeric ($row_data[$key]) ) :
						$row_data["SET_YESNO_".$key] = html_yes_no($row_data[$key],$key,$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id'].'&id='.$row_data['id'].'&pg='.$_GET["pg"]);


						$row_data["VIEW_YESNO_".$key] = html_yes_no($row_data[$key],$key,$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id'].'&id='.$row_data['id'].'&pg='.$_GET["pg"],0);
						endif;
						/*	if (strpos($field_type, 'date' ) !== false) :
						 $row_data["DATE_".$field_name] = (($row_data[$field_name])?show_date($cfg["date_format"],timestamp($row_data[$field_name])):'&nbsp;');
						 endif;
							*/
						endforeach;

						if ($_GET["keyword"]):

						$pattern = '/('.trim(strip_tags($_GET["keyword"])).')/i';

						$replacements = '<b>$1</b>';

						$row_data[$_GET["search_field"]] = cut_string(preg_replace($pattern, $replacements, trim(strip_tags($row_data[$_GET["search_field"]]))),100);

						endif;
							
						if ($row_data['image']):
						if (strpos($row_data['image'], 'http://')!==false){
							$row_data["IMAGE_URL"] = '<img src="/resize.php?w=60&url='.$row_data['image'].'" />';
						}else{
							$row_data["IMAGE_URL"] = '<img src="/resize.php?w=60&url=/'.rtrim($cfg['upload_folder'],'/').'/'.$row_data['image'].'" width="60" height="60"/>';
						}

						else:
						$row_data["IMAGE_URL"] = '';
						endif;

						if (isset ($row_data['type'])){
							global $arrType;
							$row_data['TYPE_NAME'] = $arrType[$row_data['type']];
						}
						if (isset ($row_data['status'])){
							if ($row_data['status']==1){
								$row_data['STATUS'] = 'Finish';
							}else{
								$row_data['STATUS'] = '<a href="#" onclick="order('.$row_data['id'].')"><img style="border: 1px solid #335DCF;"  src="images/buttonUpdateEng.gif"></a>';
							}

						}

						if($tbl["login_as_user"]!='' && $tbl["login_as_user"]!=NULL){
							$key=md5($row_data['id']+123);
							$row_data["login_as_user"]='<a href="http://'.$_SERVER["SERVER_NAME"].'/function/login-as-user/id/'.$row_data['id'].'/keygen/'.$key.'" target="_blank">Login</a>';
						}
							

						if (isset ($row_data['price'])){
							$row_data['PRICE'] = number_format($row_data['price'], 0,'','.');
						}
						if (isset ($row_data['price_from'])){
							$row_data['PRICE_FROM'] = number_format($row_data['price_from'], 0,'','.');
						}
						if (isset ($row_data['price_to'])){
							$row_data['PRICE_TO'] = number_format($row_data['price_to'], 0,'','.');
						}
						if (isset ($row_data['from'])){
							$row_data['from'] = number_format($row_data['from'], 0,'','.');
						}
						if (isset ($row_data['to'])){
							$row_data['to'] = number_format($row_data['to'], 0,'','.');
						}
						if ($_GET['mdl']=='car'){
							$arr = array ('mua-ban-xe-may-cu-','mua-ban-xe-oto-cu-');
							$row_data['LINK_DETAIL'] = '/'.$arr[$row_data['type']] . $row_data['id'] . '-'.$row_data['alias'] . '.html';
						}
						$row_data["DATE"] = show_date($cfg["date_format"],timestamp($row_data['created_time']));

						$row_data["TIME"] = show_date("H:i:s",timestamp($row_data['created_time']));

						$row_data["ACTIVE"] = html_yes_no($row_data['active'],'active',$index_url.'&p=show&sp=show_content&cat_id='.$_GET['cat_id'].'&id='.$row_data['id'].'&pg='.$_GET["pg"]);
							
						$row_data["PUBLIC"] = html_yes_no($row_data['active'],'active',$index_url.'&p=show&sp=show_content&id='.$row_data['id'].'&pg='.$_GET["pg"], 1, 0, 'public');

						$row_data["ITEM_TITLE"] = common_status_title($row_data['created_by'], timestamp($row_data['created_time']), $row_data['updated_by'], timestamp($row_data['updated_time']));

						$row_data["ROW_COLOR"] = ((!$row_data['active'])?'bgcolor="#EEEEEE"':'');

						//	$row_data["URL"] = $index_url.'&p=edit_content&cat_id='.$_GET['cat_id'].'&pg='.$_GET["pg"];

						$row_data["EDIT_URL"] = $index_url.'&p=edit_content&id='.$row_data['id'].'&pg='.$_GET["pg"];

						$row_data["VIEW_URL"] = $index_url.'&p=view_content&id='.$row_data['id'].'&pg='.$_GET["pg"];

						$row_data["DELETE_URL"] = $index_url.'&p=show&sp=show_content&act=delete&id='.$row_data['id'].'&pg='.$_GET["pg"];

						$row_data["ORDER_INPUT"] = html_input_sort('sort', $row_data['id'], $row_data['sort'],'blue');

						$row_data["CHECKBOX_ITEM"] = html_input_checkbox('id', $row_data['id']);

						$row_data["EDIT_ITEM"] = html_icon_edit($index_url.'&p=edit_content&id='.$row_data['id'].'&pg='.$_GET["pg"]);

						$row_data["DELETE_ITEM"] = html_icon_delete($index_url.'&p=show&sp=show_content&act=delete&cat_id='.$_GET['cat_id'].'&id='.$row_data['id'].'&pg='.$_GET["pg"]);
							
						$this->row_result .= html_data($this->row_tpl,$row_data);
							
						endwhile;

						$DB->free_result($q_content);


						$total_content = $DB->result($DB->query('SELECT FOUND_ROWS()'),0);

						if ($_GET["keyword"]):

						$result .= message('Found '.$total_content.' contents','info');

						endif;


					}

					// No data was found

					else

					$this->row_result .= '<tr><td colspan="20" align="center" class="datatd">'.message($lang["no_requested_data"],'info').'</td></tr>';



					$mdl_data = array(

						"SORT_BY" => $this->draw_form_sort(),

						"QUICK_SEARCH" => $this->draw_form_search(),

					//						"QUICK_JUMP" => $this->draw_select_cat($_SESSION[get('mdl').'_cat_table'],'','',3,1),

						"CHECKBOX_ALL" => '<input type="checkbox" name="all_id" class="box" value="all" onClick="set_all_cb(\'frm_show\',\'id[]\',\'all_id\');" title="'.$lang['checkbox_all'].'">',

					//						"MOVE_SELECTED" => $this->draw_form_move($_SESSION[get('mdl').'_cat_table'],'cat_id',3),

						"ACTION_SELECTED" => common_action_list(),

						"DELETE_SELECTED" => '<input type="submit" class="button" name="delete_selected" value="'.$lang["delete_selected"].'" onClick="return confirm(\''.$lang['js_confirm_delete_selected'].'\');">',

						"UPDATE_ORDER" => '<input type="submit" class="button" name="update_sort" value="'.$lang["update_sort"].'">',

						"HEAD_TITLE" => (($mdl_cfg['head_title'])?$mdl_cfg['head_title']:(($_SESSION[get('mdl').'_cat_table'])?'<a href="'.$index_url.'&p=show&sp=show_cat" >'.$lang["manage_contents"].'</a> &#8250; '.$cat['name']:$lang["manage_contents"])),

						"FORM_ACTION" => $index_url.'&p=show&sp=show_content&cat_id='.get('cat_id').'&pg='.get("pg"),

						"PAGE" => show_pages($total_content,$mdl_cfg["content_per_page"],$index_url.'&p='.get('p').'&sp='.get('sp').'&cat_id='.$_GET['cat_id'].'&search_field='.get("search_field").'&keyword='.get("keyword")),

						"TAB_MENU" => $this->draw_tab(),

						"CAT_OPTIONS" => $this->draw_options('cat'),

						"CONTENT_OPTIONS" => $this->draw_options('content'),

						"SID" => session_id(),

					);
                    
                    if (get('mdl')=='car'){
                        
                        $content_field = get('content_field');
                        $content_value = get('content_value');
                        
                        switch (intval($_SESSION['car_content_option'])){
                            
                            case 1:
                            case 2:
                            $content_field='';
                            break;
                            case 3:
                            $content_field='type';
                            $content_value =0;
                            
                            break;
                            case 4:
                            $content_field='type';
                            $content_value =1;
                            
                            
                            break;
                            default:
                            $content_field='';
                        }
                        if ($content_field=='type'){
                            $content['type'] = $content_value;
                            $mdl_data ['QUICK_JUMP']=$this->draw_select_cat_motor('manufacture','manu_id','name',1,'id',1);
                        }else{
                            $mdl_data ['QUICK_JUMP']=$this->draw_select_cat('manufacture','manu_id','name',1,'id');
                        }
//                        if ( get('manu_id') ){
//                            
//                            $content['manu_id']= get('manu_id');
//                            $mdl_data ['QUICK_JUMP'] .= '   '.$jcas->draw_select_cat_motor('model','model_id','name', 1,'id', 0);
//                        }
//                        
                    }
					$mdl_data['HEAD_TITLE'] .= '<br/>'. 'Total : '. $total_content;


					$result .= html_block(html_data($this->tpl,$mdl_data),"row",$this->row_result);

				}

				break;

		}

		echo html_print($result);

	}

};

?>